<?php
namespace app\index\controller;


use app\admin\model\Record;
use app\admin\model\Results;
use app\admin\model\Rewards;
use app\admin\model\System;
use app\admin\model\Userhis;
use think\Cache;
use think\Db;
use think\Session;

class Index extends Base
{

    public function index()
    {

        $ismobile = ismobile();
        if ($ismobile){
            $this->redirect('wap/index');
        }

        //统计本月累计充值最多
//        $userHis = new Userhis();
//        $rechangelist = Db::query("SELECT userhis.*,sum(data) as total,user.username as username FROM `userhis` left join user on userhis.uid=user.id where type=4 GROUP by uid order by total desc limit 0,5");
//        $gonggao = "本月充值排行榜";
//        foreach ($rechangelist as $k=>$v){
//            $gonggao.= "第".($k+1)."名:".$v['username'].",金额".round($v['total'],0)."。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
//        }
//

        //统计系统累计投注最高
//        $sql1 = "select tmp.*,sum(tmp.score) as score from
//                (select rewards.*,calToScore(reward,kid,direction,kou) as score,user.name,user.username from rewards left JOIN user on rewards.uid = user.id  ) tmp
//                group by uid order by score desc";
//        $reward = Db::query($sql1);
//        $gonggao = "投注排行:";
//        foreach ($reward as $v){
//            $gonggao.= $v['username']."累计投注:".$v['score'].",";
//        }
//        $this->assign("gonggao",$gonggao);

        //统计每日赢钱最多.
        $zerotime = date("Y-m-d")." 00:00:00";
//        $gonggao = "大神排行（今日赢取）:";
//        $sql2 = "select rewards.*,sum(win) as wintotal,user.username,user.name from rewards left JOIN user on rewards.uid = user.id WHERE create_time > ".strtotime($zerotime)." GROUP by uid ORDER by wintotal desc";
//        $winlist = Db::query($sql2);
//        foreach ($winlist as $v){
//            $gonggao.= $v['username']."今日赢取鲜花:".$v['wintotal'].",";
//        }
//        $this->assign("gonggao",$gonggao);
        $system = System::getSystem();
        $this->assign("system",$system);
        return view();
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @name 比赛概略列表
     */
    public function getUserHis()
    {
        $uid = Session::get('user')['id'];
        if (!$uid) return ['status'=>0];
        $userhis = new Userhis();
        return ['status'=>1,'data'=>$userhis->getHis($uid)];
    }

    public function getHisInfo()
    {
        $gid = input('post.gid');
        $uid = Session::get('user')['id'];
        $userHis = new Userhis();
        $data = $userHis->getHisInfo($uid,$gid);
        return ['status'=>1,'data'=>$data];
    }

    public function getUserResult()
    {
        $uid = Session::get('user')['id'];
        if (!$uid) return ['status'=>0];
        $result = new Record();
        $rs = $result->where(['uid'=>$uid])->order(['id'=>'desc'])->select();
        return ['status'=>1,"data"=>$rs];
    }

    public function test()
    {
//        Cache::set("name",123);
//        echo 123;
//        echo Cache::get("name");
        var_dump(Cache::get("name"));
    }
}
